package com.example.thread.base.a1b2c3;

import java.util.concurrent.locks.LockSupport;

/**
 * @author LiYuhang
 * @version 0.1
 * @application 使用 LockSupport 的方式打印
 * @Date 2021/6/28 11:58
 * @Description
 */
public class Print_LockSupport {
    static Thread t1 = null;
    static Thread t2 = null;
    public static void main(String[] args) {
        char[] str = "ABCDEFG".toCharArray();
        char[] num = "1234567".toCharArray();


        t1 = new Thread(()->{
            for (char n:str
            ) {
                System.out.println(n);
                LockSupport.unpark(t2);
                LockSupport.park();
            }
        },"t1");

        t2 = new Thread(()->{
            for (char s:num) {
                LockSupport.park();
                System.out.println(s);
                LockSupport.unpark(t1);
            }
        },"t2");
        t1.start();
        t2.start();
    }

}
